package com.gzhu.knowledgeAdmin.controller;

import com.gzhu.knowledgeAdmin.common.dto.CategoryAddRequest;
import com.gzhu.knowledgeAdmin.common.exception.BusinessException;
import com.gzhu.knowledgeAdmin.common.result.ErrorCode;
import com.gzhu.knowledgeAdmin.common.result.R;
import com.gzhu.knowledgeAdmin.common.vo.SceneVO;
import com.gzhu.knowledgeAdmin.service.CategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping("/template/category/add")
    public R<Boolean> addCategory(@RequestBody CategoryAddRequest categoryAddRequest){

        if (StringUtils.isBlank(categoryAddRequest.getValue())) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

        categoryService.addCategory(categoryAddRequest);

        return R.ok(true);
    }

    @GetMapping("/template/category")
    public R<List<String>> getCategory() {

        List<String> result = categoryService.getCategory();

        return R.ok(result);
    }

    @GetMapping("/template/category/scene")
    public R<List<SceneVO>> getScene(@RequestParam("category") String category) {

        List<SceneVO> list = categoryService.getScene(category);

        return R.ok(list);
    }

}
